package com.yaowk.web.mall.clothing.controller;

import com.yaowk.api.common.PageReq;
import com.yaowk.api.common.PageResp;
import com.yaowk.api.mall.clothing.model.Store;
import com.yaowk.api.mall.clothing.service.IStoreService;
import com.yaowk.api.mall.clothing.web.StoreAuditModel;
import com.yaowk.api.mall.clothing.web.StoreAuditQueryModel;
import com.yaowk.api.mall.clothing.web.StoreModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mall/clothing/store")
public class StoreController {

    @Autowired
    private IStoreService storeService;

    @GetMapping
    @ApiOperation("商户列表")
    public PageResp<StoreModel> list(String keyword, PageReq pageReq) {
        PageResp<StoreModel> pageResp = storeService.findAllOfWeb(keyword, pageReq);
        return pageResp;
    }

    @PostMapping("/register")
    @ApiOperation("商户注册")
    public Store register(Store store, @RequestParam(required = false) List<Long> sourceId) {
        store = storeService.register(store, sourceId);
        return store;
    }

    @PostMapping
    @ApiOperation("修改商户")
    public Store save(Store store) {
        store = storeService.save(store);
        return store;
    }

    @GetMapping("/audit")
    @ApiOperation("审核列表")
    public PageResp<StoreAuditModel> auditList(StoreAuditQueryModel queryModel, PageReq pageReq) {
        PageResp<StoreAuditModel> page = storeService.findAllOfAudit(queryModel, pageReq);
        return page;
    }

    @GetMapping("/audit/success/{id}")
    @ApiOperation("审核通过")
    public void auditSuccess(@PathVariable Integer id) {
        storeService.auditSuccess(id);

    }

    @GetMapping("/audit/fail/{id}")
    @ApiOperation("审核不通过")
    public void auditFail(@PathVariable Integer id, String remark) {
        storeService.auditFail(id, remark);
    }


}
